Skip to content

Commit 264b17d

Browse files
committed
Add CreatePermalinkHtaccessAction #32
1 parent 7e4943f commit 264b17d

5 files changed

Lines changed: 341 additions & 6 deletions

File tree

src/org/netbeans/modules/php/wordpress/WordPressActionsExtender.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@
4848
import org.netbeans.modules.php.spi.framework.PhpModuleActionsExtender;
4949
import org.netbeans.modules.php.spi.framework.actions.RunCommandAction;
5050
import org.netbeans.modules.php.wordpress.commands.WordPressCli;
51-
import org.netbeans.modules.php.wordpress.ui.actions.RefreshCodeCompletionAction;
51+
import org.netbeans.modules.php.wordpress.ui.actions.CreatePermalinkHtaccessAction;
5252
import org.netbeans.modules.php.wordpress.ui.actions.CreatePluginAction;
5353
import org.netbeans.modules.php.wordpress.ui.actions.CreateThemeAction;
54+
import org.netbeans.modules.php.wordpress.ui.actions.RefreshCodeCompletionAction;
5455
import org.netbeans.modules.php.wordpress.ui.actions.WordPressRunCommandAction;
5556
import org.netbeans.modules.php.wordpress.ui.options.WordPressOptions;
5657
import org.openide.util.NbBundle;
@@ -87,6 +88,7 @@ public List<? extends Action> getActions() {
8788
actions.add(CreateThemeAction.getInstance());
8889
actions.add(CreatePluginAction.getInstance());
8990
actions.add(new RefreshCodeCompletionAction());
91+
actions.add(CreatePermalinkHtaccessAction.getInstance());
9092
return actions;
9193
}
9294
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2014 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.ui.actions;
43+
44+
import java.io.IOException;
45+
import java.util.logging.Level;
46+
import java.util.logging.Logger;
47+
import org.netbeans.modules.php.api.phpmodule.PhpModule;
48+
import org.netbeans.modules.php.spi.framework.actions.BaseAction;
49+
import org.netbeans.modules.php.wordpress.modules.WordPressModule;
50+
import org.netbeans.modules.php.wordpress.ui.wizards.CreatePermalinkHtaccessPanel;
51+
import org.netbeans.modules.php.wordpress.util.WPUtils;
52+
import org.openide.DialogDescriptor;
53+
import org.openide.DialogDisplayer;
54+
import org.openide.NotifyDescriptor;
55+
import org.openide.filesystems.FileObject;
56+
import org.openide.filesystems.FileUtil;
57+
import org.openide.util.Exceptions;
58+
import org.openide.util.NbBundle;
59+
60+
/**
61+
*
62+
* @author junichi11
63+
*/
64+
public class CreatePermalinkHtaccessAction extends BaseAction {
65+
66+
private static final long serialVersionUID = -9023009833256287021L;
67+
private static final CreatePermalinkHtaccessAction INSTANCE = new CreatePermalinkHtaccessAction();
68+
private static final Logger LOGGER = Logger.getLogger(CreatePermalinkHtaccessAction.class.getName());
69+
70+
public static CreatePermalinkHtaccessAction getInstance() {
71+
return INSTANCE;
72+
}
73+
74+
private CreatePermalinkHtaccessAction() {
75+
}
76+
77+
@NbBundle.Messages("WordPressAction.name=WordPress: ")
78+
@Override
79+
protected String getFullName() {
80+
return Bundle.WordPressAction_name() + getPureName();
81+
}
82+
83+
@NbBundle.Messages("CreatePermalinkHtaccessAction.name=Create .htaccess for permalink")
84+
@Override
85+
protected String getPureName() {
86+
return Bundle.CreatePermalinkHtaccessAction_name();
87+
}
88+
89+
@NbBundle.Messages({
90+
"CreatePermalinkHtaccessAction.panel.message=<html>.htaccess file already exists. <br>Do you really want to overwrite it?",
91+
"# {0} - description",
92+
"CreatePermalinkHtaccessAction.error=Create permalink .htaccess action: {0}",
93+
"CreatePermalinkHtaccessAction.error.wproot=Not fond WordPress root",
94+
"CreatePermalinkHtaccessAction.error.template=Not fond template",
95+
"CreatePermalinkHtaccessAction.error.template.text=Can't get template text",
96+
"CreatePermalinkHtaccessAction.error.copy=Can't copy tempate file"})
97+
@Override
98+
protected void actionPerformed(PhpModule pm) {
99+
// called via shortcut
100+
if (!WPUtils.isWP(pm)) {
101+
return;
102+
}
103+
104+
WordPressModule wpModule = WordPressModule.Factory.forPhpModule(pm);
105+
FileObject wordPressRootDirecotry = wpModule.getWordPressRootDirecotry();
106+
if (wordPressRootDirecotry == null) {
107+
LOGGER.log(Level.WARNING, Bundle.CreatePermalinkHtaccessAction_error(Bundle.CreatePermalinkHtaccessAction_error_wproot()));
108+
return;
109+
}
110+
FileObject template = FileUtil.getConfigFile("Templates/WordPress/.htaccess"); // NOI18N
111+
if (template == null) {
112+
LOGGER.log(Level.WARNING, Bundle.CreatePermalinkHtaccessAction_error(Bundle.CreatePermalinkHtaccessAction_error_template()));
113+
return;
114+
}
115+
String contents = null;
116+
try {
117+
contents = template.asText("UTF-8"); // NOI18N
118+
} catch (IOException ex) {
119+
Exceptions.printStackTrace(ex);
120+
}
121+
if (contents == null || contents.isEmpty()) {
122+
LOGGER.log(Level.WARNING, Bundle.CreatePermalinkHtaccessAction_error(Bundle.CreatePermalinkHtaccessAction_error_template_text()));
123+
return;
124+
}
125+
126+
// check whether file already exits
127+
FileObject htaccessFile = wordPressRootDirecotry.getFileObject(".htaccess");
128+
if (htaccessFile != null) {
129+
CreatePermalinkHtaccessPanel panel = new CreatePermalinkHtaccessPanel()
130+
.setMessage(Bundle.CreatePermalinkHtaccessAction_panel_message())
131+
.setContents(contents);
132+
DialogDescriptor dialogDescriptor = new DialogDescriptor(panel, "Confirmation", true, DialogDescriptor.YES_NO_OPTION, null, null);
133+
if (DialogDisplayer.getDefault().notify(dialogDescriptor) != NotifyDescriptor.YES_OPTION) {
134+
return;
135+
}
136+
}
137+
try {
138+
if (htaccessFile != null) {
139+
htaccessFile.delete();
140+
}
141+
template.copy(wordPressRootDirecotry, template.getName(), template.getExt());
142+
} catch (IOException ex) {
143+
LOGGER.log(Level.WARNING, Bundle.CreatePermalinkHtaccessAction_error(Bundle.CreatePermalinkHtaccessAction_error_copy()));
144+
}
145+
}
146+
}

src/org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
NewProjectConfigurationPanel.unzipLabel.text=Unzipping :
1+
NewProjectConfigurationPanel.unzipLabel.text=Unzipping :
22
NewProjectConfigurationPanel.unzipStatusTextField.text=
33
NewProjectConfigurationPanel.useURLRadioButton.text=Use URL
44
NewProjectConfigurationPanel.useLocalFileRadioButton.text=Use Local file
@@ -24,13 +24,14 @@ NewProjectConfigurationPanel.dbCollateTextField.text=
2424
NewProjectConfigurationPanel.createConfigCheckBox.text=create wp-config.php
2525
CreateUnderscoresThemePanel.authorUriTextField.text=
2626
CreateUnderscoresThemePanel.descriptionTextField.text=
27-
CreateUnderscoresThemePanel.authorUriLabel.text=Author URI:
28-
CreateUnderscoresThemePanel.descriptionLabel.text=Description:
27+
CreateUnderscoresThemePanel.authorUriLabel.text=Author URI:
28+
CreateUnderscoresThemePanel.descriptionLabel.text=Description:
2929
CreateUnderscoresThemePanel.themeNameTextField.text=
3030
CreateUnderscoresThemePanel.authorTextField.text=
3131
CreateUnderscoresThemePanel.messageLabel.text=Please notice that license of theme is GPLv2
3232
CreateUnderscoresThemePanel.themeNameLabel.text=Theme Name:
33-
CreateUnderscoresThemePanel.authorLabel.text=Author:
34-
CreateThemePanel.themeNameLabel.text=Theme Name:
33+
CreateUnderscoresThemePanel.authorLabel.text=Author:
34+
CreateThemePanel.themeNameLabel.text=Theme Name:
3535
CreateThemePanel.themeNameTextField.text=
3636
NewProjectConfigurationPanel.useWpCliRadioButton.text=Use wp-cli
37+
CreatePermalinkHtaccessPanel.messageLabel.text=MESSAGE
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
3+
<Form version="1.5" maxVersion="1.9" type="org.netbeans.modules.form.forminfo.JPanelFormInfo">
4+
<AuxValues>
5+
<AuxValue name="FormSettings_autoResourcing" type="java.lang.Integer" value="1"/>
6+
<AuxValue name="FormSettings_autoSetComponentName" type="java.lang.Boolean" value="false"/>
7+
<AuxValue name="FormSettings_generateFQN" type="java.lang.Boolean" value="true"/>
8+
<AuxValue name="FormSettings_generateMnemonicsCode" type="java.lang.Boolean" value="true"/>
9+
<AuxValue name="FormSettings_i18nAutoMode" type="java.lang.Boolean" value="true"/>
10+
<AuxValue name="FormSettings_layoutCodeTarget" type="java.lang.Integer" value="1"/>
11+
<AuxValue name="FormSettings_listenerGenerationStyle" type="java.lang.Integer" value="0"/>
12+
<AuxValue name="FormSettings_variablesLocal" type="java.lang.Boolean" value="false"/>
13+
<AuxValue name="FormSettings_variablesModifier" type="java.lang.Integer" value="2"/>
14+
</AuxValues>
15+
16+
<Layout>
17+
<DimensionLayout dim="0">
18+
<Group type="103" groupAlignment="0" attributes="0">
19+
<Group type="102" attributes="0">
20+
<EmptySpace max="-2" attributes="0"/>
21+
<Group type="103" groupAlignment="0" attributes="0">
22+
<Group type="102" attributes="0">
23+
<Component id="messageLabel" min="-2" max="-2" attributes="0"/>
24+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
25+
</Group>
26+
<Component id="jScrollPane1" pref="438" max="32767" attributes="0"/>
27+
</Group>
28+
<EmptySpace max="-2" attributes="0"/>
29+
</Group>
30+
</Group>
31+
</DimensionLayout>
32+
<DimensionLayout dim="1">
33+
<Group type="103" groupAlignment="0" attributes="0">
34+
<Group type="102" alignment="0" attributes="0">
35+
<EmptySpace max="-2" attributes="0"/>
36+
<Component id="messageLabel" min="-2" max="-2" attributes="0"/>
37+
<EmptySpace max="-2" attributes="0"/>
38+
<Component id="jScrollPane1" pref="167" max="32767" attributes="0"/>
39+
<EmptySpace max="-2" attributes="0"/>
40+
</Group>
41+
</Group>
42+
</DimensionLayout>
43+
</Layout>
44+
<SubComponents>
45+
<Component class="javax.swing.JLabel" name="messageLabel">
46+
<Properties>
47+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
48+
<ResourceString bundle="org/netbeans/modules/php/wordpress/ui/wizards/Bundle.properties" key="CreatePermalinkHtaccessPanel.messageLabel.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
49+
</Property>
50+
</Properties>
51+
</Component>
52+
<Container class="javax.swing.JScrollPane" name="jScrollPane1">
53+
<AuxValues>
54+
<AuxValue name="autoScrollPane" type="java.lang.Boolean" value="true"/>
55+
</AuxValues>
56+
57+
<Layout class="org.netbeans.modules.form.compat2.layouts.support.JScrollPaneSupportLayout"/>
58+
<SubComponents>
59+
<Component class="javax.swing.JTextArea" name="contentsTextArea">
60+
<Properties>
61+
<Property name="columns" type="int" value="20"/>
62+
<Property name="rows" type="int" value="5"/>
63+
</Properties>
64+
</Component>
65+
</SubComponents>
66+
</Container>
67+
</SubComponents>
68+
</Form>
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
/*
2+
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3+
*
4+
* Copyright 2014 Oracle and/or its affiliates. All rights reserved.
5+
*
6+
* Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7+
* Other names may be trademarks of their respective owners.
8+
*
9+
* The contents of this file are subject to the terms of either the GNU
10+
* General Public License Version 2 only ("GPL") or the Common
11+
* Development and Distribution License("CDDL") (collectively, the
12+
* "License"). You may not use this file except in compliance with the
13+
* License. You can obtain a copy of the License at
14+
* http://www.netbeans.org/cddl-gplv2.html
15+
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16+
* specific language governing permissions and limitations under the
17+
* License. When distributing the software, include this License Header
18+
* Notice in each file and include the License file at
19+
* nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
20+
* particular file as subject to the "Classpath" exception as provided
21+
* by Oracle in the GPL Version 2 section of the License file that
22+
* accompanied this code. If applicable, add the following below the
23+
* License Header, with the fields enclosed by brackets [] replaced by
24+
* your own identifying information:
25+
* "Portions Copyrighted [year] [name of copyright owner]"
26+
*
27+
* If you wish your version of this file to be governed by only the CDDL
28+
* or only the GPL Version 2, indicate your decision by adding
29+
* "[Contributor] elects to include this software in this distribution
30+
* under the [CDDL or GPL Version 2] license." If you do not indicate a
31+
* single choice of license, a recipient has the option to distribute
32+
* your version of this file under either the CDDL, the GPL Version 2 or
33+
* to extend the choice of license to its licensees as provided above.
34+
* However, if you add GPL Version 2 code and therefore, elected the GPL
35+
* Version 2 license, then the option applies only if the new code is
36+
* made subject to such option by the copyright holder.
37+
*
38+
* Contributor(s):
39+
*
40+
* Portions Copyrighted 2014 Sun Microsystems, Inc.
41+
*/
42+
package org.netbeans.modules.php.wordpress.ui.wizards;
43+
44+
/**
45+
*
46+
* @author junichi11
47+
*/
48+
public class CreatePermalinkHtaccessPanel extends javax.swing.JPanel {
49+
50+
private static final long serialVersionUID = -2916411786261985237L;
51+
52+
/**
53+
* Creates new form CreatePermalinkHtaccessPanel
54+
*/
55+
public CreatePermalinkHtaccessPanel() {
56+
initComponents();
57+
messageLabel.setText(" "); // NOI18N
58+
}
59+
60+
public CreatePermalinkHtaccessPanel setMessage(String message) {
61+
messageLabel.setText(message);
62+
return this;
63+
}
64+
65+
public CreatePermalinkHtaccessPanel setContents(String contents) {
66+
contentsTextArea.setText(contents);
67+
return this;
68+
}
69+
70+
/**
71+
* This method is called from within the constructor to initialize the form.
72+
* WARNING: Do NOT modify this code. The content of this method is always
73+
* regenerated by the Form Editor.
74+
*/
75+
@SuppressWarnings("unchecked")
76+
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
77+
private void initComponents() {
78+
79+
messageLabel = new javax.swing.JLabel();
80+
jScrollPane1 = new javax.swing.JScrollPane();
81+
contentsTextArea = new javax.swing.JTextArea();
82+
83+
org.openide.awt.Mnemonics.setLocalizedText(messageLabel, org.openide.util.NbBundle.getMessage(CreatePermalinkHtaccessPanel.class, "CreatePermalinkHtaccessPanel.messageLabel.text")); // NOI18N
84+
85+
contentsTextArea.setColumns(20);
86+
contentsTextArea.setRows(5);
87+
jScrollPane1.setViewportView(contentsTextArea);
88+
89+
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
90+
this.setLayout(layout);
91+
layout.setHorizontalGroup(
92+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
93+
.addGroup(layout.createSequentialGroup()
94+
.addContainerGap()
95+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
96+
.addGroup(layout.createSequentialGroup()
97+
.addComponent(messageLabel)
98+
.addGap(0, 0, Short.MAX_VALUE))
99+
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE))
100+
.addContainerGap())
101+
);
102+
layout.setVerticalGroup(
103+
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
104+
.addGroup(layout.createSequentialGroup()
105+
.addContainerGap()
106+
.addComponent(messageLabel)
107+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
108+
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 167, Short.MAX_VALUE)
109+
.addContainerGap())
110+
);
111+
}// </editor-fold>//GEN-END:initComponents
112+
113+
// Variables declaration - do not modify//GEN-BEGIN:variables
114+
private javax.swing.JTextArea contentsTextArea;
115+
private javax.swing.JScrollPane jScrollPane1;
116+
private javax.swing.JLabel messageLabel;
117+
// End of variables declaration//GEN-END:variables
118+
}

0 commit comments

Comments
 (0)