-
Notifications
You must be signed in to change notification settings - Fork 951
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5b4062f
commit 5e865f5
Showing
10 changed files
with
1,669 additions
and
1,669 deletions.
There are no files selected for viewing
876 changes: 438 additions & 438 deletions
876
grails-encoder/src/main/groovy/org/grails/buffer/StreamByteBuffer.java
Large diffs are not rendered by default.
Oops, something went wrong.
152 changes: 76 additions & 76 deletions
152
grails-encoder/src/main/groovy/org/grails/encoder/impl/URLCodecFactory.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,76 @@ | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.encoder.impl; | ||
|
||
import groovy.transform.CompileStatic | ||
import org.grails.encoder.CodecFactory | ||
import org.grails.encoder.CodecIdentifier | ||
import org.grails.encoder.Decoder | ||
import org.grails.encoder.DefaultCodecIdentifier | ||
import org.grails.encoder.Encoder | ||
|
||
/** | ||
* Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding. | ||
* | ||
* @see <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1">Chapter 17.13.4 Form content types</a> | ||
* of the <a href="http://www.w3.org/TR/html4/">HTML 4.01 Specification</a> | ||
* | ||
* @since 2.4 | ||
*/ | ||
@CompileStatic | ||
public class URLCodecFactory implements CodecFactory { | ||
static final CodecIdentifier URL_CODEC_IDENTIFIER = new DefaultCodecIdentifier("URL"); | ||
|
||
Encoder encoder = new Encoder() { | ||
@Override | ||
public CodecIdentifier getCodecIdentifier() { | ||
URL_CODEC_IDENTIFIER; | ||
} | ||
|
||
public Object encode(Object o) { | ||
if(o==null) return o; | ||
URLEncoder.encode(String.valueOf(o), resolveEncoding()); | ||
} | ||
|
||
public boolean isApplyToSafelyEncoded() { | ||
true; | ||
} | ||
|
||
public boolean isSafe() { | ||
true; | ||
} | ||
|
||
public void markEncoded(CharSequence string) { | ||
|
||
} | ||
}; | ||
|
||
Decoder decoder = new Decoder() { | ||
public CodecIdentifier getCodecIdentifier() { | ||
URL_CODEC_IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Object decode(Object o) { | ||
if(o==null) return o; | ||
URLDecoder.decode(String.valueOf(o), resolveEncoding()); | ||
} | ||
}; | ||
|
||
protected String resolveEncoding() { | ||
'UTF-8' | ||
} | ||
} | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.encoder.impl; | ||
|
||
import groovy.transform.CompileStatic | ||
import org.grails.encoder.CodecFactory | ||
import org.grails.encoder.CodecIdentifier | ||
import org.grails.encoder.Decoder | ||
import org.grails.encoder.DefaultCodecIdentifier | ||
import org.grails.encoder.Encoder | ||
|
||
/** | ||
* Implements the 'www-form-urlencoded' encoding scheme, also misleadingly known as URL encoding. | ||
* | ||
* @see <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1">Chapter 17.13.4 Form content types</a> | ||
* of the <a href="http://www.w3.org/TR/html4/">HTML 4.01 Specification</a> | ||
* | ||
* @since 2.4 | ||
*/ | ||
@CompileStatic | ||
public class URLCodecFactory implements CodecFactory { | ||
static final CodecIdentifier URL_CODEC_IDENTIFIER = new DefaultCodecIdentifier("URL"); | ||
|
||
Encoder encoder = new Encoder() { | ||
@Override | ||
public CodecIdentifier getCodecIdentifier() { | ||
URL_CODEC_IDENTIFIER; | ||
} | ||
|
||
public Object encode(Object o) { | ||
if(o==null) return o; | ||
URLEncoder.encode(String.valueOf(o), resolveEncoding()); | ||
} | ||
|
||
public boolean isApplyToSafelyEncoded() { | ||
true; | ||
} | ||
|
||
public boolean isSafe() { | ||
true; | ||
} | ||
|
||
public void markEncoded(CharSequence string) { | ||
|
||
} | ||
}; | ||
|
||
Decoder decoder = new Decoder() { | ||
public CodecIdentifier getCodecIdentifier() { | ||
URL_CODEC_IDENTIFIER; | ||
} | ||
|
||
@Override | ||
public Object decode(Object o) { | ||
if(o==null) return o; | ||
URLDecoder.decode(String.valueOf(o), resolveEncoding()); | ||
} | ||
}; | ||
|
||
protected String resolveEncoding() { | ||
'UTF-8' | ||
} | ||
} |
76 changes: 38 additions & 38 deletions
76
grails-plugin-codecs/src/main/groovy/org/grails/commons/CodecArtefactHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,38 @@ | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.commons; | ||
|
||
import grails.core.ArtefactHandlerAdapter; | ||
import org.grails.core.artefact.DomainClassArtefactHandler; | ||
|
||
/** | ||
* @author Marc Palmer ([email protected]) | ||
*/ | ||
public class CodecArtefactHandler extends ArtefactHandlerAdapter { | ||
|
||
public static final String TYPE = "Codec"; | ||
|
||
public CodecArtefactHandler() { | ||
super(TYPE, GrailsCodecClass.class, DefaultGrailsCodecClass.class, TYPE); | ||
} | ||
|
||
@Override | ||
public boolean isArtefactClass(@SuppressWarnings("rawtypes") Class clazz) { | ||
if (clazz == null) return false; | ||
|
||
return clazz.getName().endsWith(DefaultGrailsCodecClass.CODEC) && !DomainClassArtefactHandler.isDomainClass(clazz); | ||
} | ||
} | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.commons; | ||
|
||
import grails.core.ArtefactHandlerAdapter; | ||
import org.grails.core.artefact.DomainClassArtefactHandler; | ||
|
||
/** | ||
* @author Marc Palmer ([email protected]) | ||
*/ | ||
public class CodecArtefactHandler extends ArtefactHandlerAdapter { | ||
|
||
public static final String TYPE = "Codec"; | ||
|
||
public CodecArtefactHandler() { | ||
super(TYPE, GrailsCodecClass.class, DefaultGrailsCodecClass.class, TYPE); | ||
} | ||
|
||
@Override | ||
public boolean isArtefactClass(@SuppressWarnings("rawtypes") Class clazz) { | ||
if (clazz == null) return false; | ||
|
||
return clazz.getName().endsWith(DefaultGrailsCodecClass.CODEC) && !DomainClassArtefactHandler.isDomainClass(clazz); | ||
} | ||
} |
62 changes: 31 additions & 31 deletions
62
grails-plugin-codecs/src/main/groovy/org/grails/plugins/codecs/URLCodec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,31 @@ | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.plugins.codecs | ||
|
||
import org.grails.encoder.impl.URLCodecFactory | ||
import org.springframework.web.context.request.RequestContextHolder | ||
|
||
/** | ||
* A codec that encodes and decodes Objects to and from URL encoded strings. | ||
* | ||
* @author Marc Palmer | ||
* @since 0.5 | ||
*/ | ||
class URLCodec extends URLCodecFactory { | ||
protected String resolveEncoding() { | ||
RequestContextHolder.getRequestAttributes()?.request?.characterEncoding ?: 'UTF-8' | ||
} | ||
} | ||
/* | ||
* Copyright 2024 original authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.grails.plugins.codecs | ||
|
||
import org.grails.encoder.impl.URLCodecFactory | ||
import org.springframework.web.context.request.RequestContextHolder | ||
|
||
/** | ||
* A codec that encodes and decodes Objects to and from URL encoded strings. | ||
* | ||
* @author Marc Palmer | ||
* @since 0.5 | ||
*/ | ||
class URLCodec extends URLCodecFactory { | ||
protected String resolveEncoding() { | ||
RequestContextHolder.getRequestAttributes()?.request?.characterEncoding ?: 'UTF-8' | ||
} | ||
} |
Oops, something went wrong.